/**
 * 
 */
package co.fitstart.admin.entity.content;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.Filter;
import com.demo2do.core.persistence.support.Order;
import com.demo2do.core.persistence.support.QueryBuilder;

import co.fitstart.entity.coupon.CouponBatch;

/**
 * @author mohanlan
 *
 */
public class CouponSearch implements QueryBuilder {
	
	private String contactPerson;
	
	private String identification;
	
	private CouponBatch batch;
	
	/** 截止日开始时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    
    /** 截止日结束时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
	
	private Order order;

    private Filter filter;
    
    /**
     * default constructor
     */
    public CouponSearch() {
        order = new Order("createTime", "DESC");
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public Filter getPreparedFilter(boolean refresh) {

        if(filter == null || refresh) {
            filter =  new Filter()
            			  .addEquals("identification", identification)
            			  .addEquals("contactPerson", contactPerson)
            			  .addEquals("batch", batch)
            			  .addDateBetween("createTime", beginDate, endDate);
        }

        return filter;
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM Coupon " + getPreparedFilter(false).getWhereSentence() + order.getSentence();
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).getParameters();
    }

	/**
	 * @return the contactPerson
	 */
	public String getContactPerson() {
		return contactPerson;
	}

	/**
	 * @return the identification
	 */
	public String getIdentification() {
		return identification;
	}

	/**
	 * @return the batch
	 */
	public CouponBatch getBatch() {
		return batch;
	}

	/**
	 * @return the beginDate
	 */
	public Date getBeginDate() {
		return beginDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @return the order
	 */
	public Order getOrder() {
		return order;
	}

	/**
	 * @return the filter
	 */
	public Filter getFilter() {
		return filter;
	}

	/**
	 * @param contactPerson the contactPerson to set
	 */
	public void setContactPerson(String contactPerson) {
		this.contactPerson = contactPerson;
	}

	/**
	 * @param identification the identification to set
	 */
	public void setIdentification(String identification) {
		this.identification = identification;
	}

	/**
	 * @param batch the batch to set
	 */
	public void setBatch(CouponBatch batch) {
		this.batch = batch;
	}

	/**
	 * @param beginDate the beginDate to set
	 */
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @param order the order to set
	 */
	public void setOrder(Order order) {
		this.order = order;
	}

}
